package thread;

public class SyncDemo3 {
    public static void main(String[] args) {
        Foo f1 = new Foo();
        Foo f2 = new Foo();
        Thread t1 = new Thread() {
            @Override
            public void run() {
                f1.doSome();
            }
        };
        Thread t2 = new Thread() {
            @Override
            public void run() {
                f2.doSome();
            }
        };
        t1.start();
        t2.start();
    }
}

class Foo {
    /**
     * 静态方法全局就一份，同步执行（表示有先后顺序）
     */
   // public  synchronized static void doSome() {
    public   static void doSome() {
        try {
            synchronized (Foo.class) {
                Thread t = Thread.currentThread();
                System.out.println(t.getName() + "正在执行doSome方法...");
                Thread.sleep(5000);
                System.out.println(t.getName() + "执行doSome方法完毕！");
            }
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
    }
}

